<template>
	<view class="">
		<!-- <view class="head_content">
			<CustomNavbar title="剧场" color="#fff" bg="#000"></CustomNavbar>
		</view> -->
		<web-view ref="webview" :src="baseUrl" v-if="baseUrl" @onPostMessage="handlePostMessage"  @load="loadWebview" @message="handleMessage"></web-view>
	</view>
</template>

<script>
	let _option = {}
	import store from '@/common/store/index.js'
	import { ApplePay } from '../../common/utils/applePay.js'
	import { h5Address } from '../../env.js'

	export default {
		name: '',
		data() {
			return {
				baseUrl: '',
				applePay: null
			}
		},
		onLoad(option) {
			_option = option
			// var isAndroid = uni.getSystemInfoSync().platform == 'android'
			// if (!isAndroid){
			//   this.isAndroid = isAndroid
			//   this.loadAppleChannel()
			// }
			// // #ifdef H5
			// setTimeout(() => {
			//   uni.showLoading({ title:'Loading...' })
			// }, 100)
			// // #endif
			this.applePay = new ApplePay()
		},
		onShow() {
			const token = store.state.user.token || ''
			console.log(token, 'token')
			const {
				videoAutoplay,
				config
			} = store.state.app
			// if (!token) {
			// 	store.dispatch('user/logout')
			// 	uni.showModal({
			// 		title: '系统提示',
			// 		content: '本操作需要您进行登录验证',
			// 		success: res => {
			// 			if (res.confirm) {
			// 				uni.navigateTo({ url: '/pages/login/login' })
			// 			}else{
			// 				uni.navigateBack()
			// 			}
			// 		}
			// 	})
			// 	return
			// }
			
      
			this.baseUrl =
				`${h5Address}/pages/video/detail?token=${token}&videoAutoplay=${videoAutoplay}&config=${config}&id=${_option.id}&d=${_option.d}`
			// this.baseUrl =
			// 	`http://192.168.15.137:8082/app/pages/video/detail?token=${token}&videoAutoplay=${videoAutoplay}&config=${config}&id=${_option.id}&d=${_option.d}`
		},
    onReady() {
			//获取webview页面
			var currentWebview = this.$mp.page.$getAppWebview().children()[0]
			 
			console.log(JSON.stringify(currentWebview),'currentWebview')
			//监听加载完毕  关闭loading
			currentWebview.addEventListener('loaded', function() {
				uni.hideLoading()
				// plus.nativeUI.closeWaiting()
			}, false)
		},
		methods: {
      loadWebview(){
				console.log(123,'124')
				uni.hideLoading()
			},
			// webview向外部发送消 
			handlePostMessage: function(data) {
				console.log('接收到消息：' + JSON.stringify(data.detail))
			},
			handleMessage(data) {
				console.log('接收到消息：' + JSON.stringify(data.detail))
				if (data.detail.data) {
					const detail = data.detail.data[0]
					let vm = this
					detail.navType && uni[detail.navType]({ url: detail.url })
					if (detail.type == 'back') {
						uni.navigateBack()
					} else if (detail.type == 'home') {
						uni.switchTab({ url: '/pages/home/index' })
					} else if (detail.type == 'login') {
						uni.navigateTo({ url: '/pages/login/login' })
					}
				}
				console.log('handleMessage33', data.detail.data[0].type)
			}
		},
		components: {},
	}
</script>

<style>

</style>